package com.example.flowerpcback.controller;

import com.example.flowerpcback.services.TagService;
import com.example.flowerpcback.services.TestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.concurrent.TimeUnit;


@RestController //这是返回接口
@RequestMapping("/test")
public class TestController {

    private static final Logger LOG = LoggerFactory.getLogger(TestController.class);

    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private TestService testService;

    @GetMapping("/getTest")
    public String getTest(){
        return  "getTest成功99!!";
    }

    @GetMapping("/setRedis/set/{key}/{value}")
    public String setRedis(@PathVariable Long key, @PathVariable String value){
        redisTemplate.opsForValue().set(key,value,3600, TimeUnit.SECONDS);
        return  "success";
    }

    @GetMapping("/setRedis/get/{key}")
    public Object getRedis(@PathVariable Long key){
        Object object = redisTemplate.opsForValue().get(key);
        LOG.info("value",object.toString());
        return  object;
    }

    @GetMapping("/testpwd")
    public String testpwd(@Valid String pwd){
        return  DigestUtils.md5DigestAsHex(pwd.getBytes());
    }

    @GetMapping("/getAliyunoss")
    public void getAliyunoss() throws Exception {
        testService.aliyunoss();
    }

}

